/*
 * defines.h
 *
 *  Created on: Mar 27, 2013
 *      Author: locpm
 */
#include <sys/timeb.h>

#ifndef DEFINES_H_
#define DEFINES_H_

#define MAX_CMD_BUFF 256

// Number of moves that we can store (all plies)
#define MAX_MOV_BUFF 4096

// Search depth
#define MAX_PLY 64

// Number of moves in the (game + search) line that we can store
#define MAX_GAME_LINE 1024

typedef unsigned char BOOL;

typedef unsigned int U32;

typedef unsigned long long U64;

typedef struct {
	U32 bb[3];
} BITBOARD;

typedef struct
{
	// from (7 bits) The from square identified by a number from 0 to 89, using 7 bits
	// tosq (7 bits) The to square identified by a number from 0 to 89, using 7 bits
	// piec (4 bits) The moving piece that identified by a number from 0 to 15, using 4 bits
	// capt (4 bits) The captured piece that identified by a number from 0 to 15, using 4 bits
	// This int variable is 32-bit length, we use 7 + 7 + 4 + 4 = 22 bits, the last 10 bits is ignored
	unsigned int moveInt;
} MOVE;

typedef struct
{
       MOVE move;
} GAMELINERECORD;

typedef struct
{
	U64 startTime;
	U64 stopTime;
	U64 currentTime;
	U64 stopTimeDelta;
	struct timeb startBuffer;
	struct timeb stopBuffer;
	struct timeb currentBuffer;
	BOOL running;
} TIMER;

typedef struct
{
	// bitboards to store a chess position
	BITBOARD whiteKing, whiteAdvisors, whiteElephants, whiteRooks, whiteCannons, whiteHorses, whitePawns;
	BITBOARD blackKing, blackAdvisors, blackElephants, blackRooks, blackCannons, blackHorses, blackPawns;
	BITBOARD whitePieces, blackPieces, occupiedSquares;

	// incrementally updated, this array is usefull if we want to
	// probe what kind of piece is on a particular square.
	int square[90];

	// WHITE_MOVE or BLACK_MOVE
	unsigned char nextMove;

	// only used for displaying the board. TRUE or FALSE.
	BOOL viewRotated;

    // storing moves:
	// all generated moves of the current search tree are stored in this array.
	MOVE moveBuffer[MAX_MOV_BUFF];

    // this arrays keeps track of which moves belong to which ply
    int moveBufLen[MAX_PLY];

    GAMELINERECORD gameLine[MAX_GAME_LINE];

    // index for gameLine
    int endOfGame;

    // index for gameLine
    int endOfSearch;

    // Search depth
    int searchDepth;

    // search variables:
    int triangularLength[MAX_PLY];
    MOVE triangularArray[MAX_PLY][MAX_PLY];

    U64 msStart, msStop;
    U64 inodes;

    TIMER timer;

    int lastPVLength;
    MOVE lastPV[MAX_PLY];
    unsigned int whiteHeuristics[90][90];
    unsigned int blackHeuristics[90][90];
    BOOL followpv;
} BOARD;

#if defined(_WIN32)
#define PRINTF_INT64_MODIFIER "I64"
#else
#define PRINTF_INT64_MODIFIER "ll"
#endif

#endif /* DEFINES_H_ */
